<template>
  <div class="box">
    <!-- 头部 -->
    <div class="hear">
      <span><img
          :src="baseURL+(data.account&&data.account.defaultAvatar)"
          alt=""
        ></span>&nbsp;&nbsp;
      <span>{{data.account&&data.account.nickname}}</span>&nbsp;&nbsp;
      <span>{{moment(data.updated_at).format('YYYY-MM-DD HH:mm:ss')}}</span>
    </div>
    <!-- 中间的嵌套评论 -->
    <commentItem
      v-if="data.parent"
      :parent='data.parent'
      @replydata='reply'
      class="item"
    ></commentItem>
    <!-- 当前的评论 -->
    <div class="s_box">
      <div class="comment">{{data.content}}</div>
      <span
        class="img"
        v-for="(item,index) in data.pics"
        :key='index'
      ><img
          :src="baseURL+item.url"
          alt=""
        ></span>
      <div class="reply">
        <a
          href="javascript:;"
          @click="reply((data.id),(data.account&&data.account.nickname))"
        >回复</a>
      </div>

    </div>
  </div>
</template>

<script>
import commentItem from "@/components/post/recursionComment";
import axios from "@/utils/myaxios";
import moment from "moment";
export default {
  props: ["data"],
  data() {
    return {
      baseURL: axios.defaults.baseURL,
    };
  },
  methods: {
    moment,
    reply(id, nickname) {
      this.$emit("replydata", id, nickname);
    },
  },
  components: {
    commentItem,
  },
};
</script>

<style lang="less" scoped>
.box {
  width: 100%;
  border-bottom: 1px dashed #ddd;
  padding: 20px 0;
  // padding-bottom: 5px;
  // background-color: pink;

  .hear {
    font-size: 12px;
    color: #666666;
    display: flex;
    margin-bottom: 10px;

    span {
      height: 16px;

      img {
        width: 16px;
        height: 16px;
        border-radius: 8px;
      }
    }
  }

  .item {
    margin-left: 20px;
  }

  .s_box {
    position: relative;
    &:hover .reply a {
      display: block;
    }

    .comment {
      padding-left: 25px;
      margin-top: 10px;
    }

    .img {
      display: inline-block;
      width: 80px;
      height: 80px;
      padding: 5px;
      border: 1px dashed #ddd;
      border-radius: 6px;
      margin: 10px 5px 0 25px;

      img {
        width: 100%;
        height: 100%;
      }
    }
    .reply {
      height: 14px;
      display: flex;
      justify-content: flex-end;
      a {
        display: none;
        color: #1e50a2;
        font-size: 12px;
      }
    }
  }
}
</style>